package cn.tedu.eb_film.service.impl;


import cn.tedu.eb_film.mapper.UserCommentMapper;
import cn.tedu.eb_film.pojo.dto.UserCommentDTO;
import cn.tedu.eb_film.pojo.entity.UserComment;
import cn.tedu.eb_film.pojo.vo.UserCommentStandardVO;
import cn.tedu.eb_film.service.UserCommentService;
import cn.tedu.eb_film.utils.JsonResult;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 评论表(UserComment)表服务实现类
 *
 * @author makejava
 * @since 2023-03-14 18:53:44
 */
@Service("userCommentService")
public class UserCommentServiceImpl implements UserCommentService {
    @Resource
    private UserCommentMapper userCommentMapper;



    /**
     * 新增数据
     *
     * @param userComment 实例对象
     * @return 实例对象
     */
    @Override
    public void insert(UserComment userComment) {
       userCommentMapper.insert(userComment);
    }

    /**
     * 批量新增评论
     * @param list
     */
    @Override
    public void addList(List<UserComment> list) {
        userCommentMapper.addList(list);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public void deleteById(Long id) {
        userCommentMapper.deleteById(id);
    }

    /**
     * 通过ids删除数据
     * @param list
     */
    @Override
    public void deleteByIdList(List<Long> list) {
        userCommentMapper.deleteByIdList(list);
    }

    /**
     * 统计数据
     */
    @Override
    public void count(UserComment userComment) {
        userCommentMapper.count(userComment);
    }

    @Override
    public BigDecimal avgScore(Long id) {
        BigDecimal avgScore = userCommentMapper.avgScore(id);
        return avgScore;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public List<UserComment> queryById(Long id) {

        List<UserComment> list = userCommentMapper.queryById(id);
        return list;
    }

    /**
     * 获取用户评论列表
     * @return
     */
    @Override
    public List<UserComment> getCommentList() {
        List<UserComment> list =userCommentMapper.getCommentList();
        return list;
    }

    /**
     * 修改数据
     *
     * @param userComment 实例对象
     * @return 实例对象
     */
    @Override
    public void update(UserComment userComment) {
        userCommentMapper.update(userComment);

    }


    @Override
    public List<UserCommentStandardVO> getUserName(Long id) {
        List<UserCommentStandardVO> userName = userCommentMapper.getUserName(id);
        return userName;
    }

    @Override
    public void addNew(UserCommentDTO userCommentDTO) {
        UserComment userComment = new UserComment();
        BeanUtils.copyProperties(userCommentDTO,userComment);
        LocalDateTime localDateTime=LocalDateTime.now();
        userComment.setCreateTime(localDateTime);
        userComment.setUpdateTime(localDateTime);
        userCommentMapper.insert(userComment);
    }

}
